package com.itcc.service.impl;

import com.itcc.dao.ProductDao;
import com.itcc.dao.impl.ProductDaoImpl;
import com.itcc.entity.PageBean;
import com.itcc.entity.Product;
import com.itcc.service.ProductService;

import java.sql.SQLException;
import java.util.List;

public class ProductServiceImpl implements ProductService {
    @Override
    public PageBean<Product> findPage(String tid, int page, int pageSize) throws SQLException {

        ProductDao productDao=new ProductDaoImpl();

        long count=productDao.selectCountByTid(tid);//总记录数

        List<Product> list=productDao.selectProductByPage(page,pageSize,tid);

        return new PageBean<Product>(list,page,pageSize,count);
    }

    @Override
    public Product findProductByPid(String pid) throws SQLException {
        ProductDao productDao=new ProductDaoImpl();

        Product product=productDao.selectProductByPid(pid);

        return product;
    }

    @Override
    public List<Product> findAllProducts() throws SQLException {
        ProductDao productDao=new ProductDaoImpl();

        List<Product> productList=productDao.selectProduct();

        return productList;
    }

    @Override
    public void addProduct(Product product) throws SQLException {

        ProductDao productDao=new ProductDaoImpl();
        productDao.insertProduct(product);
    }

    @Override
    public void deleteProduct(String pid) throws SQLException {

        ProductDao productDao=new ProductDaoImpl();
        productDao.deleteByPid(pid);
    }

    @Override
    public void updateProduct(Product product) throws SQLException {
         ProductDao productDao=new ProductDaoImpl();
         productDao.updateByPid(product);
    }
}
